Skip to content

Harden query sandbox, add tests and CI, refresh README - #1

Open
Praso28 wants to merge 2 commits into
mainfrom
production-hardening
Open

Praso28 wants to merge 2 commits into
mainfrom
production-hardening

Conversation

@Praso28

@Praso28 Praso28 commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Requested by P · project thread

What this does

Brings SQLBomb up to production grade without changing the game itself (same story, stages, data and look).

Safer query engine (backend/db.py)

Players type arbitrary SQL into the live app. Before this PR, queries ran against one shared on-disk SQLite file with only a regex filter in front, and an unbounded recursive CTE could hang the app. Now:

  • every query runs in a fresh in-memory database seeded from database/*.sql, so nothing can leak between players,
  • a SQLite authorizer allows reads only (writes, ATTACH, PRAGMA, schema changes are denied by the engine),
  • one statement per query, a 2 s time limit, and a 500-row cap.

Better player experience

  • Real SQL errors (e.g. no such column: nope) are shown instead of silently showing "no results". They are HTML-escaped.
  • Rejected queries get a specific reason.
  • WITH / CTE queries, -- comments, and keywords inside string literals (e.g. 'Drop Table') now work.
  • Verification answers are case-insensitive (airport = Airport).

Cleanup

  • Removed dead timer code and unused tuple-result branches (which also had a bug: 'bomb_id.*2' in row_str was a literal-string check).
  • Removed the Heroku Procfile/setup.sh and duplicate requirements-streamlit.txt; stopped disabling XSRF protection in .streamlit/config.toml.
  • Dropped unused python-dateutil; bounded dependency versions.
  • Readme.md → README.md, rewritten with the live link, sandbox design and dev instructions.

Tests and CI

  • 39 pytest tests: sandbox (blocked writes, timeout, row cap, multi-statement), validation, each stage's completion rule including decoys, and a full UI playthrough using Streamlit's AppTest.
  • .github/workflows/ci.yml runs ruff check and pytest on Python 3.10 to 3.13.

Before merging

  • The live app at https://sqlbomb.streamlit.app/ redeploys from main. The code now needs Python 3.10+; if the Streamlit Cloud app is set to an older Python, change it under the app's Settings first.
  • I couldn't reach the live app from my environment, so I verified locally with streamlit run and the AppTest playthrough.

Test plan

  • ruff check .
  • pytest (39 passed locally on Python 3.13)
  • CI green on this PR
  • Play through once on the live app after merge

Generated by Claude Code

- Run every player query in a fresh in-memory SQLite DB with a read-only
  authorizer, a 2s time limit and a 500-row cap
- Surface real SQL errors to players (escaped) instead of silently
  returning no rows; give specific messages for rejected queries
- Allow WITH/CTE queries, SQL comments and keywords inside string literals
- Make verification answers case-insensitive
- Remove dead timer code and unused tuple-result code paths
- Drop Heroku Procfile/setup.sh and the duplicate requirements file;
  stop disabling XSRF protection in Streamlit config
- Add pytest suite (sandbox, validation, stage rules, full UI playthrough
  via AppTest) and a GitHub Actions workflow for ruff + pytest on 3.10-3.13
- Rewrite README with live link, sandbox design and dev instructions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwKFojwA2s9TbXcrR6Mzqg
@Praso28 Praso28 self-assigned this Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants